
 begintownscript;

 variables;

 int i,j,k,r1,choice;

 body;

 beginstate INIT_STATE;

	add_char_to_group(7,1);
	add_char_to_group(12,1);
	add_char_to_group(13,1);
	add_char_to_group(14,1);
	add_char_to_group(23,1);
	add_char_to_group(24,1);
	add_char_to_group(25,1);
	add_char_to_group(26,1);
	add_char_to_group(28,2);
	add_char_to_group(29,2);
	add_char_to_group(30,2);
	add_char_to_group(31,2);
	add_char_to_group(32,2);
	add_char_to_group(33,2);

	set_name(8,"Messothsss");
	set_name(9,"Miner");
	set_name(10,"Ossso");

	set_level(8,25);
	set_level(10,26);
	set_level(27,30);

	if (get_flag(5,2) == 5)
		erase_char(10);

	if ((get_flag(5,12) == 1 || get_flag(100,1) > 0) && get_flag(5,13) == 1) {
		erase_char(11);
}

break;

 beginstate START_STATE;

	approach_waypoint(7,0,3);

	if (get_flag(100,1) != 0)
		approach_char(34,0,6);

break;

 beginstate EXIT_STATE;

	if (character_in_party(999) > 0 && get_flag(5,13) == 1)
		message_dialog("When you've reach the sunlight again, Ossso speaks to you. _Friendss while I have enjoyed your company, I wissh to return home. If you could help me find a way to get to Avernum quickly I would be mosst grateful.","");

break;

 beginstate 10;
	if (get_flag(5,3) == 0) {
		message_dialog("You open the box, in it you find mostly blankets and the sorts. Digging a little deeper, however reveals a small iron key.","");
		set_flag(5,3,1);
		change_spec_item(3,1);
}
break;

 beginstate 11;
	if (get_flag(5,4) == 0) {
		message_dialog("Unlike the miners' quarters the guards' quarters look recently built. Perhaps the guards were fed up with having to share their beds with miners so they decided to build quarters of their own. It doesn't really matter now.","Right now, however, slith have taken over the quarters. By the sound of it, most of them are located to your right.");
		set_flag(5,4,1);
}
break;

 beginstate 12;
	if (get_flag(5,5) == 0 && has_special_item(3) == 1) {
		message_dialog("You listen closely, there is discussion going on in the room ahead of you. You hear two voices; the first is definitely a slith, but the other is a low, sinister growling voice.","");
	set_flag(5,5,1);

}
break;

 beginstate 13;
	if (has_special_item(3) == 0)
		message_dialog("You try the door. It's locked up tight. There is no way you can get it open.","");
break;

 beginstate 14;
	if (get_flag(5,6) == 0) {
		message_dialog("The mines have been taken by sliths. How they got here from Avernum is a mystery which you hope to solve. You inspect the mines. There are dried bloodstains everywhere and bodies of dead miners. No doubt this is supposed to make you nervous.","You also hear the hissing of slithzerikai. The sound is coming closer.");
		set_flag(5,6,1);
}
break;

 beginstate 15;
	if (get_flag(5,7) == 0) {
		message_dialog("Looks like the miners tried to make a stand in their quarters. They weren't successful. All you see is bodies pierced by slith spears. Judging from the smell, the bodies have been lying here for at least a week.","");
		set_flag(5,7,1);
}
break;

 beginstate 16;
	if (get_flag(5,8) == 0 && char_ok(34) == TRUE) {
		message_dialog("It is not uncommon that sliths train cave lizard to fight by their side. You were beginning to think these slith did not do so. You were wrong. A massive cave lizard slithers towards you with a hungry look on its face.","");
		set_flag(5,8,1);
}
break;

 beginstate 17;
	if (get_flag(5,9) == 0) {
		message_dialog("You've entered a burial site. A quick glimpse at the tombstones reveals that these slith were killed when the slith conquered the mines. At least the miners put up a fight.","");
		set_flag(5,9,1);
}
break;

 beginstate 18;
	if (get_flag(5,10) == 0) {
		reset_dialog();
		add_dialog_str(0,"This poor miner managed to crawl into hiding when he was wounded, unfortunately that's where his luck ended. He has a javelin sticking out of his stomach. This wasn't a painless death.",0);
		add_dialog_str(1,"Looking more closely, you notice the man had, and still has, a necklace around his neck. It has a falcon flying towards a crescent moon.",0);
		add_dialog_choice(0,"Take the necklace.");
		add_dialog_choice(1,"Leave the necklace.");
		choice = run_dialog(1);

	if (choice == 1) {
		change_spec_item(4,1);
		set_flag(5,10,1);
}
}
break;

 beginstate 19;
	if (get_flag(5,11) == 0) {
		reset_dialog();
		add_dialog_str(0,"The slith archmage has taken this room as his own. There are a lot of scrolls containing magical writings on the shelves.",0);
		add_dialog_str(1,"One particular scroll catches your eye. The runes on it seem extremely ancient. You could try to decipher them, if you wish.",0);
		add_dialog_choice(0,"Try to read the runes.");
		add_dialog_choice(1,"Leave."); 
		choice = run_dialog(1);

		if (choice == 1 && get_skill_total(42 >= 45))
			set_state_continue(21);

		if (choice == 1 && get_skill_total(42 < 45))
			set_state_continue(22);
}
break;

 beginstate 20;
	if (has_item(319) == 1 && get_flag(5,0) == 0) {
		reset_dialog();
		add_dialog_str(0,"The wall looks like it would give in, if you found the right tools. Fortunately you have a pick ax. With a little effort you could tear down the wall.",0);
		add_dialog_choice(0,"Smash!");
		add_dialog_choice(1,"Do nothing.");
		choice = run_dialog(1);

	if (choice == 1) {
		swap_terrain(40,54,35,137);
		play_sound(41);
		pause(2);
		play_sound(108);
		set_flag(5,0,1);
}
}
 break;

 beginstate 21;
	message_dialog("The runes are indeed ancient. fortunately you are skilled enough to understand what they are about. You improve your information on the Arcane Blow spell.","");
	j = get_selected_pc();
	i = 0;
	while (i < 4) {
		if (((j < 0) || (j == i)) && (char_ok(i))) {
			set_flag(5,11,1);
			change_spell_level(i,0,19,1);
		}
		i = i + 1;
	}
break;

 beginstate 22;
	message_dialog("The runes are indeed very old. Deciphering them is a demanding task which you cannot carry off.","");
break;

 beginstate 23;
	reset_dialog();
	add_dialog_str(0,"The book you find does not contain magic spells. Instead it contains the entries of the slith archmage. This is his journal. You open the book and immediately turn to the more recent notes.",0);
	add_dialog_str(1,"The sliths were teleported to the surface by a powerful haakai, who did not reveal his name to the slith. The haakai didn't even bother to speak with the slith, for that he had a minion.",0);
	add_dialog_str(2,"The minion is a mung demon known as Marnok. He gave the slith chieftain a magical weapon and instantly won him over. The slith were ordered to attack the human settlement, meaning Sattle, east of the mines.",0);
	add_dialog_str(3,"The last entry has been made today. _Today Marnok will again be approaching us. Messothsss seems to trust him completely, but I have my doubts. What will the demons do to us when they no longer need us?_",0);
	add_dialog_str(4,"_I will approach Messothsss after the demon has gone. Hopefully he will listen._",0);
	run_dialog(1);
 break;

 beginstate 24;
	set_flag(5,0,1);
 break;